package com.nbsaas.boot.manufacturing.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.AbstractEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Data;
import org.hibernate.annotations.Comment;

import java.math.BigDecimal;
import java.util.Date;

@CreateByUser
@ComposeView
@Data
@FormAnnotation(title = "生产计划", model = "生产计划")
@Entity
@Table(name = "bs_production_plan")
@Comment("生产计划表")
public class ProductionPlan extends AbstractEntity {

    @Comment("计划编号")
    @SearchItem(name = "planNo", key = "planNo", label = "计划编号")
    @FormField(title = "计划编号", sortNum = "1", grid = true, required = true)
    @Column(length = 50, nullable = false, unique = true)
    private String planNo;

    @Comment("计划名称")
    @SearchItem(name = "name", key = "name", label = "计划名称")
    @FormField(title = "计划名称", sortNum = "2", grid = true, required = true)
    @Column(length = 200, nullable = false)
    private String name;

    @Comment("计划类型")
    @FormField(title = "计划类型", sortNum = "3", grid = true, type = InputType.select)
    @Column(length = 50)
    private String planType; // MASTER-主生产计划, MATERIAL-物料需求计划, CAPACITY-产能计划

    @Comment("计划周期")
    @FormField(title = "计划周期", sortNum = "4", grid = true, type = InputType.select)
    @Column(length = 20)
    private String planPeriod; // DAILY-日计划, WEEKLY-周计划, MONTHLY-月计划

    @Comment("计划开始日期")
    @FormField(title = "计划开始日期", sortNum = "5", type = InputType.date, grid = true, required = true)
    private Date planStartDate;

    @Comment("计划结束日期")
    @FormField(title = "计划结束日期", sortNum = "6", type = InputType.date, grid = true, required = true)
    private Date planEndDate;

    @Comment("产品ID")
    @FormField(title = "产品", sortNum = "7", grid = true, type = InputType.select)
    private Long productId;

    @Comment("产品SKU ID")
    @FormField(title = "产品SKU", sortNum = "8", grid = true, type = InputType.select)
    private Long productSkuId;

    @Comment("计划数量")
    @FormField(title = "计划数量", sortNum = "9", grid = true, type = InputType.el_input_number, required = true)
    private Integer plannedQuantity;

    @Comment("实际数量")
    @FormField(title = "实际数量", sortNum = "10", grid = true, type = InputType.el_input_number)
    private Integer actualQuantity;

    @Comment("完成数量")
    @FormField(title = "完成数量", sortNum = "11", grid = true, type = InputType.el_input_number)
    private Integer completedQuantity;

    @Comment("计划状态")
    @FormField(title = "计划状态", sortNum = "12", grid = true, type = InputType.select)
    @Column(length = 20)
    private String status; // DRAFT-草稿, CONFIRMED-已确认, IN_PROGRESS-执行中, COMPLETED-已完成, CANCELLED-已取消

    @Comment("优先级")
    @FormField(title = "优先级", sortNum = "13", grid = true, type = InputType.select)
    @Column(length = 20)
    private String priority; // HIGH-高, MEDIUM-中, LOW-低

    @Comment("计划来源")
    @FormField(title = "计划来源", sortNum = "14", grid = true, type = InputType.select)
    @Column(length = 50)
    private String planSource; // SALES_ORDER-销售订单, FORECAST-预测, INVENTORY-库存补充

    @Comment("来源订单号")
    @FormField(title = "来源订单号", sortNum = "15", grid = true)
    @Column(length = 100)
    private String sourceOrderNo;

    @Comment("客户名称")
    @FormField(title = "客户名称", sortNum = "16", grid = true)
    @Column(length = 200)
    private String customerName;

    @Comment("交货日期")
    @FormField(title = "交货日期", sortNum = "17", type = InputType.date, grid = true)
    private Date deliveryDate;

    @Comment("工艺路线ID")
    @FormField(title = "工艺路线", sortNum = "18", grid = true, type = InputType.select)
    private Long processRouteId;

    @Comment("生产车间ID")
    @FormField(title = "生产车间", sortNum = "19", grid = true, type = InputType.select)
    private Long workshopId;

    @Comment("生产线ID")
    @FormField(title = "生产线", sortNum = "20", grid = true, type = InputType.select)
    private Long productionLineId;

    @Comment("标准工时(小时)")
    @FormField(title = "标准工时(小时)", sortNum = "21", grid = true, type = InputType.el_input_number)
    private BigDecimal standardHours;

    @Comment("实际工时(小时)")
    @FormField(title = "实际工时(小时)", sortNum = "22", grid = true, type = InputType.el_input_number)
    private BigDecimal actualHours;

    @Comment("标准成本")
    @FormField(title = "标准成本", sortNum = "23", grid = true, type = InputType.el_input_number)
    @Column(precision = 10, scale = 2)
    private BigDecimal standardCost;

    @Comment("实际成本")
    @FormField(title = "实际成本", sortNum = "24", grid = true, type = InputType.el_input_number)
    @Column(precision = 10, scale = 2)
    private BigDecimal actualCost;

    @Comment("计划完成率(%)")
    @FormField(title = "计划完成率(%)", sortNum = "25", grid = true, type = InputType.el_input_number)
    @Column(precision = 5, scale = 2)
    private BigDecimal completionRate;

    @Comment("质量要求")
    @FormField(title = "质量要求", sortNum = "26", type = InputType.richText, col = 23)
    @Column(columnDefinition = "TEXT")
    private String qualityRequirements;

    @Comment("特殊要求")
    @FormField(title = "特殊要求", sortNum = "27", type = InputType.richText, col = 23)
    @Column(columnDefinition = "TEXT")
    private String specialRequirements;

    @Comment("备注")
    @FormField(title = "备注", sortNum = "28", type = InputType.richText, col = 23)
    @Column(length = 1000)
    private String note;

    @Comment("审核状态")
    @FormField(title = "审核状态", sortNum = "29", grid = true, type = InputType.select)
    @Column(length = 20)
    private String auditStatus; // PENDING-待审核, APPROVED-已审核, REJECTED-已拒绝

    @Comment("审核人")
    @FormField(title = "审核人", sortNum = "30", grid = true)
    private Long auditor;

    @Comment("审核时间")
    @FormField(title = "审核时间", sortNum = "31", type = InputType.date, grid = true)
    private Date auditTime;

    @Comment("审核意见")
    @FormField(title = "审核意见", sortNum = "32", type = InputType.richText, col = 23)
    @Column(length = 1000)
    private String auditOpinion;
} 